package com.newlink.building.main.mvp.model

import com.newlink.building.common_base.base.BaseModel
import com.newlink.building.common_base.http.Base_RetrofitHelper
import com.newlink.building.common_base.model.bean.*
import com.newlink.building.common_base.utils.MqttDoorOperator
import com.newlink.building.main.mvp.contract.Module_Main_HomeContract
import io.reactivex.Observable

/**
 * Created by xiaodong on 2022/9/26.
 */
class Module_Main_HomeModel : BaseModel(), Module_Main_HomeContract.Model {

    override fun getDeviceList(request: DeviceListRequest): Observable<HttpResult<DeviceListData>> {
        return Base_RetrofitHelper.service.getDeviceList(
            request.accessToken,
            request.page,
            request.limit,
            request.devName,
            request.devType
        )
    }

    override fun getDoorInfo(
        token: String,
        mac: String,
    ): Observable<HttpResult<MutableList<DoorData>>> {
        return Base_RetrofitHelper.service.getDoorInfo(token, mac)
    }

    override fun openDoorAction(request: OpenDoorRequest) {
        MqttDoorOperator.sendOpenDoorAction(
            request.uId,
            request.mac,
            request.whichDoor,
            request.action
        )
    }

    override fun getMissedCalls(token: String): Observable<HttpResult<Int>> {
        return Base_RetrofitHelper.service.getMissedCalls(token)
    }

    override fun getUnreadFlag(
        token: String,
        type: Int,
    ): Observable<HttpResult<MessageReadResult>> {
        return Base_RetrofitHelper.service.getUnreadFlag(token, type)
    }

    override fun getRecordUnreadPrompt(
        token: String,
        prjId: Long
    ): Observable<HttpResult<RecordMessageReadResult>> {
        return Base_RetrofitHelper.service.getRecordUnreadPrompt(token, prjId)
    }

    override fun getPrjList(token: String): Observable<HttpResult<MutableList<ProjectData>>> {
        return Base_RetrofitHelper.service.getPrjList(token)
    }
}